package com.baoyi.xml.hander;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.XMLReader;

import com.baoyi.domain.Pic;

public class HandlerApps {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SAXParserFactory factory = SAXParserFactory.newInstance();
		List<Pic> info = new ArrayList<Pic>();
		try {
			String xml = "directoryxml/main_directory.xml";
			InputStream inputStream = HandlerApps.class.getClassLoader()
					.getResourceAsStream(xml);
			URL url = new URL("http://192.168.1.27:8080/picweb/data/main_directory.xml");
			HttpURLConnection urlConn = (HttpURLConnection)url.openConnection();
			inputStream=urlConn.getInputStream();
			SAXParser parser = factory.newSAXParser();
			XMLReader xmlreader = parser.getXMLReader();
			NetImageHandler healHandler = new NetImageHandler("keai");
			xmlreader.setContentHandler(healHandler);
			parser.parse(inputStream, healHandler);
			System.out.println(healHandler.getPics().size());
		} catch (Exception e) {
			e.printStackTrace();
		} // TODO Auto-generated method stub

	}

}
